//---------------------------------------------------------------------------

#ifndef USBCANInterfaceH
#define USBCANInterfaceH

#include "FTD2XX.H"
#include "DebugWinU.h"
#include "CIISCommon.h"

//---------------------------------------------------------------------------
const canMSG_STD = 0002; // Message to CIINet ( via USBCANInterface )
const USBCanMSG  = 0100; // Message to USBCANInterface
const TempCANBufSize = 1023;
const CANInBufSize = 1023;
const  BufMask = 1023;
const  USBHeaderLength = 5;
const  MaxUSBMeassageLength = 15;


class TUSBCANInterface : public TObject
{
private:
  TDebugWin *DW;
  ProcMessFP PM;
  FT_HANDLE CurrentFTHandle;
  TTimer *TimerCanRx;
  Byte TempCANBuf[TempCANBufSize + 1];
  Byte CANInBuf[CANInBufSize + 1];
  int CANInBufReadPnt, CANInBufWritePnt;
  Byte CANInMsg[8];
  Cardinal CANInFlg;

        int FCanBusStatus;
        int FUSBCanVersion;
        int __fastcall GetUSBCanVersion();
        void __fastcall Debug(String Message);
        bool __fastcall SetCANPower(bool Status);
protected:

public:
        __fastcall TUSBCANInterface( ProcMessFP SetPM, TDebugWin *SetDebugWin);
        int __fastcall SendMsg(int id, byte * msg, Cardinal dlc, Cardinal flags);
        bool __fastcall CanBusOn();
				bool __fastcall CanBusOff();
				bool __fastcall CanBusOff_2();
				bool __fastcall SetAOut(Word CanAdr, int Value);
				bool __fastcall SetPSVOut(Word CanAdr, int Value);
				bool __fastcall SetPSIOut(Word CanAdr, int Value);
				bool __fastcall SetDigOut(Word CanAdr, Word Channel, bool Status);
				bool __fastcall SetPSOutputOn(Word CanAdr, bool Status);
				bool __fastcall SetPSMode(Word CanAdr, int Status);
        bool __fastcall SetUSBCanActive(bool Status);
        bool __fastcall SetUSBCanAddress(Word USBCANAddress);
        void __fastcall SetDebugWin(TDebugWin *SetDebugWin);
__published:
        void __fastcall TimerCanRxEvent(TObject * Sender);
        __property int CanBusStatus  = { read=FCanBusStatus, write=FCanBusStatus };
        __property int USBCanVersion  = { read=FUSBCanVersion, write=FUSBCanVersion };

};





#endif
